﻿Imports Oracle.DataAccess.Client
Public Class fListaMarcas

    Private lIdMarca As String
    Public ReadOnly Property mMarca() As String
        Get
            Return lIdMarca
        End Get
    End Property

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT IDMARCA, DESCRIPCION FROM PRO_MARCAS "
        Dim qWhere As String = ""
        If Me.txtDecripcionMarca.Text.Trim.Length > 0 Then
            qWhere = "WHERE DESCRIPCION LIKE '%" & txtDecripcionMarca.Text & "%'"
        End If
        Try
            Conn.Open()
            cmd.CommandText &= qWhere
            DsProductos.PRO_MARCAS.Clear()
            DsProductos.PRO_MARCAS.Load(cmd.ExecuteReader)
            Conn.Close()
            PRO_MARCASDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub

    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub PRO_MARCASDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PRO_MARCASDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lIdMarca = PRO_MARCASDataGridView.Rows(e.RowIndex).Cells("IDMARCA").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaMarca(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIdMarca = PRO_MARCASDataGridView.Rows(Fila).Cells("IDMARCA").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub


    Private Sub PRO_MARCASDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PRO_MARCASDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaMarca(PRO_MARCASDataGridView.CurrentRow.Index)
        End If

    End Sub

    Private Sub txtDecripcionMarca_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDecripcionMarca.KeyDown
        Try

            Select Case e.KeyCode
                Case 13
                    consultar()
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class